package com.chilly.lambda;

/**
 * 方法和构造函数引用(Method and Constructor References)
 * 通过 ::关键字传递方法或构造函数的引用
 * Created by Chilly Cui on 2020/11/19.
 */
public class MethodLambda {
    public static void main(String[] args) {
        Converter<String,Integer> converter = Integer::valueOf;
        Integer converted = converter.convert("456");
        System.out.println(converted.getClass());

        //引用对象方法
        Something something = new Something();
        Converter<String, String> startWith = something::startWith;
        String s = startWith.convert("Java");
        System.out.println(s);
    }
}

class Something{
    String startWith(String s){
        return String.valueOf(s.charAt(0));
    }
}